package org.bigjava.biz.impl;

import org.bigjava.bean.Garbage;
import org.bigjava.bean.Ljql;
import org.bigjava.biz.GarbageService;
import org.bigjava.biz.LjqlService;
import org.bigjava.mapper.LjqlMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Service;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

@Service("ljqlService")
public class LjqlServiceImpl implements LjqlService {
    @Qualifier("ljqlMapper")
    @Autowired
    LjqlMapper  ljqlMapper;

    @Autowired
    GarbageService garbageService;

    //根据垃圾站点名称查询或垃圾清理日期查询
    @Override
    public List<Ljql> ljqlMoHu(int g_id, String qlrq) {
        return ljqlMapper.ljqlMoHu(g_id,qlrq);
    }
    //根据id修改垃圾清理信息
    @Override
    public int ljqlXiuGai(Ljql ljql) {
        SimpleDateFormat s = new SimpleDateFormat("yyyy:MM:dd HH:mm:ss");
        Ljql ljqla = ljqlId(ljql.getId());
        //自动化修改垃圾清理编号
        Garbage garbage = garbageService.garbageId(ljql.getG_id());
        String qlrq = s.format(ljql.getQlrq()).substring(0,8).replace(":","0");
        String qlbh = qlrq + garbage.getZdbh();
        ljql.setQlbh(qlbh);
        //清理的时间
        Date date = new Date();
        String format = s.format(date);
        ljql.setCleanTime(format);

        return ljqlMapper.ljqlXiuGai(ljql);
    }
    //根据id查垃圾清理信息
    @Override
    public Ljql ljqlId(int id) {
        return ljqlMapper.ljqlId(id);
    }
    //根据id假删除
    @Override
    public int ljqlShanChu(int id) {
        return ljqlMapper.ljqlShanChu(id);
    }
    //垃圾清理信息总数
    @Override
    public int ljqlZong() {
        return ljqlMapper.ljqlZong();
    }
    //垃圾清理信息分页查询
    @Override
    public List<Ljql> ljqlFenYe(int offset, int length) {
        return ljqlMapper.ljqlFenYe(offset,length);
    }
    //添加垃圾清理信息
    @Override
    public int ljqlAdd(Ljql ljql) {
        SimpleDateFormat s = new SimpleDateFormat("yyyy:MM:dd HH:mm:ss");
        //设置清理时间
        Date date = new Date();
        String format = s.format(date);
        ljql.setCleanTime(format);
        //设置垃圾清理编号
        Garbage garbage = garbageService.garbageId(ljql.getG_id());
        String qlrq = s.format(ljql.getQlrq()).substring(0,8).replace(":","0");
        String qlbh = qlrq + garbage.getZdbh();
        ljql.setQlbh(qlbh);
        return ljqlMapper.ljqlAdd(ljql);
    }
}
